<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="include/includeTablebase"></head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form class="form-inline" role="form" style="float: left; width: 100%;" method="post" id="queryInformation">
                <div class="form-group">
                    <label for="title">资讯标题:</label>
                    <input type="text" class="form-control" name="title" id="title" placeholder="请输入资讯标题"/>
                </div>

                <div class="form-group">
                    <label for="consultContent">咨询内容:</label>
                    <input type="text" class="form-control" name="consultContent" id="consultContent"
                           placeholder="请输入咨询内容"/>
                </div>
                <div class="form-group">
                    <label for="type">咨询类型:</label>
                    <select class="form-control" name="type" id="type">

                    </select>
                </div>


                <div class="form-group">
                    <button type="button" id="queryBtn" onclick="doQuery();" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
    <table id="infor_table" style="margin-top: -50px;">
    </table>
</div>
<script th:inline="javascript">
    $(function () {
        setTimeout('initTable()', 100);
        $.post("dict/getType", {type: "INFORMATION_TYPE"},
            function (r) {
                for (var i = 0; i <= r.data.length; i++) {
                    if (r.data.length == i) {
                        $("#type").append("<option  selected=true value=" + "%%"+ " >" +"</option>");
                    } else {
                        $("#type").append("<option value=" + r.data[i].value + ">" + r.data[i].text + "</option>");
                    }
                }
            });
    });

    function doQuery() {
        // 移除遮罩层的属性否则会导致在移动端无法显示滚动条
        $('body').removeClass("modal-open");
        $('#infor_table').bootstrapTable('refresh');    //刷新表格
    }

    function initTable() {
        console.log("909090");
        $.fn.bTableUtil({
            id: "infor_table",
            url: "information/list",
            formId: "queryInformation",
            sortName: 'id',
            sortOrder: 'desc',
            toolbars: [
                {
                    text: '添加',
                    iconCls: 'glyphicon glyphicon-plus',
                    code: 'add_sys_information',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        window.Ewin.dialog({
                            title: "添加",
                            url: "information/addPage",
                            gridId: "gridId",
                            width: 400,
                            height: 500
                        })
                    }
                },
                {
                    text: '修改',
                    iconCls: 'glyphicon glyphicon-pencil',
                    code: 'edit_sys_information',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#infor_table').bootstrapTable('getSelections');
                        if (rows.length == 0 || rows.length > 1) {
                            window.Ewin.alert({message: '请选择一条需要修改的数据!'});
                            return false;
                        }
                        window.Ewin.dialog({
                            title: "修改",
                            url: "information/updatePage?id=" + rows[0].id,
                            gridId: "gridId",
                            width: 400,
                            height: 500
                        });
                    }
                },
                {
                    text: '删除',
                    iconCls: 'glyphicon glyphicon-remove',
                    code: 'remove_sys_information',
                    verify: false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#infor_table').bootstrapTable('getSelections');
                        if (rows.length == 0) {
                            window.Ewin.alert({message: '请选择一条需要删除的数据!'});
                            return false;
                        }
                        window.Ewin.confirm({title: '提示', message: '是否要删除您所选择的记录？', width: 500}).on(function (e) {
                            if (e) {
                                $.post("information/removeBath", {json: JSON.stringify(rows)}, function (e) {
                                    if (e.result) {
                                        window.Ewin.alert({message: e.msg});
                                        doQuery();
                                    }
                                });
                            }
                        });
                    }
                },
                {
                    text: '重新加载',
                    iconCls: 'glyphicon glyphicon-record',
                    verify: false,
                    handler: function () {
                        window.Ewin.confirm({title: '提示', message: '是否要需要重新加载数据？', width: 500}).on(function (e) {
                            if (e) {
                                $.post("information/reload", function (e) {
                                    if (e.result) {
                                        window.Ewin.alert({message: e.msg});
                                    }
                                });
                            }
                        });
                    }
                }
            ],
            columns: [
                {
                    checkbox: true
                },
                {
                    field: '',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    field: 'title',
                    title: '资讯标题',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'consultContent',
                    title: '资讯内容',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                },
                {
                    field: 'type',
                    title: '咨询类型',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                }]
        });
    }
</script>
</body>
</html>